var id=localStorage.getItem("id")
var vm = new Vue({
    el:"#ljw1",
    data:{
        name:"",
        contact:"",
        phone:"",
        address:"",
        dHouse:"",
        remark:""
    },
    mounted(){
        axios({
            url:"/purchase/showSp",
            params:{
                id:id
            },
            method:"post"
        }).then(response=>{
            console.log(response)
            vm.name = response.data.obj.name
            vm.contact=response.data.obj.contact
            vm.phone=response.data.obj.phone
            vm.address=response.data.obj.address
            vm.dHouse=response.data.obj.dHouse
            vm.remark=response.data.obj.remark
        })
    }
})

$("#baocun").click(
    function checkPhone(){
        var phone = document.getElementById('user-email1').value;
        var name=$("#user-name").val()
        var cangku=$("#user-name1").val()
        var lxr=$("#user-email2").val()
        var dizhi=$("#user-phone").val()
        var beizhu=$("#user-weibo").val()
        if((/^1[3456789]\d{9}$/.test(phone))){
            if(name!=null && name!=""){
                if(cangku!=null && cangku!=""){

                        if(lxr!=null && lxr!=""){

                            if(dizhi!=null && dizhi!=""){
                                var a={
                                    id:id,
                                    name:name,
                                    contact:lxr,
                                    phone:phone,
                                    address:dizhi,
                                    remark:beizhu,
                                    dHouse:cangku
                                }
                                $.ajax({
                                    url:"/purchase/updaSp",
                                    data:JSON.stringify(a),
                                    dataType:"Json",
                                    type:"post",
                                    contentType: 'application/json; charset=UTF-8',
                                    async:false,
                                    success:function (dto) {

                                        var ad=JSON.parse(dto)
                                        if(ad.obj>0){
                                            alert("修改成功")
                                            location.href="供应商管理.html"
                                        }else{
                                            alert("修改失败")
                                        }

                                    }
                                })
                            }else{
                                alert("请输入地址")
                            }
                        }else{
                            alert("请输入联系人")
                        }
                }else{
                    alert("请选择默认仓库")
                }
            }else{
                alert("请输入供应商名称")
            }
        }else{
            alert("手机号码有误，请重填");
        }
    }
)